package Y2024.M11.D21;

import java.io.File;
import java.io.IOException;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 25228
 * Date: 2024-11-21
 * Time: 8:03
 */
public class Main {
    public static void main(String[] args) throws IOException {
        Student student=new Student();
        try {
            student.setAge(131);
        }catch (AgeException ex){
            System.out.println("年龄不合法");
        }


        File file=new File("./resource/");
        file.mkdir();
        for (int i = 0; i < 100; i++) {
            File file1=new File(file,i+".txt");
            file1.createNewFile();
        }
        FileTree fileTree=new FileTree();
        fileTree.tree(new File("./"),0);
    }
}
class Student{
    String name;
    int age;

    public void setName(String name) {
        this.name = name;
    }

    public void setAge(int age) throws AgeException {
        if (age<=0||age>=120){
            throw new AgeException("年龄不合法");
        }
        this.age = age;
    }
}
class AgeException extends Exception{
    AgeException(String s){
         super(s);
    }
}
class FileTree{
    File file;
    void tree(File file,int val){
        // 打印当前文件或目录
        System.out.println(val + file.getName());

        // 如果是目录，则递归遍历其内容
        if (file.isDirectory()) {
            File[] files = file.listFiles();
            if (files != null) {
                for (File f : files) {
                    printFileTree("f,val+   ");
                }
            }
        }
    }
    void printFileTree(String directoryPath) {
        File directory = new File(directoryPath);
        if (directory.exists() && directory.isDirectory()) {
            printFileTree(directory+"");
        } else {
            System.out.println("Invalid directory path: " + directoryPath);
        }
    }
}